import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ClassroomView from '../views/ClassroomView.vue'
import CannibalismView from '../views/CannibalismView.vue'
import FavoriteView from '../views/FavoriteView.vue'
import MyView from '../views/MyView.vue'


Vue.use(VueRouter)
// 独享路由守卫
let beforeEnter = (to,from,next)=>{
  let token = window.localStorage.getItem("token");
  // 判断是否登录
  if(!token){
    next("/login");
    return;
  }else{
    next();
  }
}

const routes = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
  
  },
  {
    path: '/class',
    name: 'class',
    component: ClassroomView,
  
  },
  {
    path: '/cannibalism',
    name: 'cannibalism',
    component: CannibalismView,
  },
  {
    path: '/favorite',
    name: 'favorite',
    component: FavoriteView,
  },
  {
    path: '/my',
    name: 'my',
    component: MyView,
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/DetailsPage.vue'),

  },
  {
    path: '/novice',
    name: 'novice',
    component: () => import('../views/NoviceRecipe.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/SearchView.vue')
  },
  {
    path: '/categorize',
    name: 'categorize',
    component: () => import('../views/CategorizationView.vue')
  },
  {
    path: '/author',
    name: 'author',
    component: () => import('../views/AuthorView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/LoginView.vue')
  },
  {
    path: '/ranking',
    name: 'ranking',
    component: () => import('../views/RankingList.vue')
  },
  {
    path: '/basket',
    name: 'basket',
    component: () => import('../views/BasketView.vue'),
    beforeEnter
  },
  {
    path: '/sign',
    name: 'sign',
    component: () => import('../views/SigninView.vue')
  },
  {
    path: '/publicRanking',
    name: 'publicRanking',
    component: () => import('../views/PublicRankingList.vue')
  },
  {
    path: '/cooklist',
    name: 'cooklist',
    component: () => import('../views/CooklistView.vue')
  },
  {
    path: '/simpletalk',
    name: 'simpletalk',
    component: () => import('../views/SimpleTalkDetail.vue')
  },
  {
    path: '/course',
    name: 'course',
    component: () => import('../views/CourseDetail.vue')
  },
  {
    path: '/coursealbum',
    name: 'coursealbum',
    component: () => import('../views/CourseAlbum.vue')
  },
  {
    path: '/allComment',
    name: 'allComment',
    component: () => import('../views/AllComment.vue')
  },
  {
    path: '/myworks',
    name: 'myworks',
    component: () => import('../views/MyWorks.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
